import React, {Component, PropTypes} from 'react';
import {Row, Col, Button, Table, Icon, Tag} from 'antd';

function strSub(str) {
  if (str != null) {
    if (str.length > 45) {
      return str.substring(0, 45) + "...";
    } else {
      return str;
    }
  }
}

function strCSub(str) {
  if (str != null) {
    if (str.length > 22) {
      return str.substring(0, 22) + "...";
    } else {
      return str;
    }
  }
}

class ShowListContainer extends Component {
  constructor(props) {
    super(props);
    this.state = {
      data: [],
    };
  }

  onRowClick(e) {
    this.props.listSignal.dispatch(e.id);
  }

  updateData(listData) {
    var oldData = this.state.data;
    for (var d in oldData) {
      if (listData.id == oldData[d].id) {
        oldData[d].comment = listData.comment;
      }
    }
    this.setState(
      {
        data: oldData
      }
    )
  }

  render() {

    const InfoRender = (text, record) => {
      if (record.type == 3) {
        return (
          <span>
            <Icon type="file-text"/>&nbsp;&nbsp;&nbsp;{strSub(text)}
            <br/>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{strCSub(record.comment)}
          </span>

        )
      } else {
        return null;
      }
    }

    const columns = [{
      title: '内容列表',
      dataIndex: 'name',
      key: 'name',
      render: (text, record) => (
        InfoRender(text, record)
      ),
    }];

    return (
      <div>
        <Table dataSource={this.state.data}
               onRowClick={this.onRowClick.bind(this)}
               columns={columns} pagination={false} size="middle"
               rowKey={record => record.id}
               scroll={{ y: 600 }} />
      </div>
    );
  }
}

export default ShowListContainer;
